(function(){
	function getQuerystring(key, default_)
	{
	  if (default_==null) default_="";
	  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	  var qs = regex.exec(window.location.href);
	  if(qs == null)
		return default_;
	  else
		return qs[1];
	}
	
	function defaultInitial () {
		CJ.Channel.getData(function(){
			CJ.Scene.channel();
		},
		null,
		function(){
			$('#mask').removeClass('black');
			CJ.Loading.off();
		});
	}

	$(document).ready(function(){
		var paramPID = getQuerystring("titleid", "");
		if (!!paramPID) {
			CJ.HttpJson.get({
				type: 'RETURNCHANNELCODE',
				param: {
					programid: paramPID
				},
				success:  function (json) {
					if (json.resultcode == 100){
						//CJ.Program.getData(json.channelid);
						CJ.Program.getData(json.channelid, null, function() {		// 2013.08.13 by SINZINET
							CJ.Scene["Program"].setFocus(paramPID);
							CJ.Scene["Program"].pageNum();
							CJ.Scene["Program"].searchProgramID = paramPID;
						});
						CJ.Episode.getData(paramPID);
						CJ.Channel.getData(function() {
							CJ.Scene["Channel"].setFocus(json.channelid);
							CJ.Scene["Channel"].searchProgramID = paramPID;
						});
					} else {
						defaultInitial();
					}
				},
				complete: function () {
					$('#mask').removeClass('black');
					CJ.Loading.off();
				}
			});

		} else {
			defaultInitial();
		}
	});

})();